package com.ruoyi.asset.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.asset.domain.SysExpendDetailsAsset;
import com.ruoyi.asset.service.ISysExpendDetailsAssetService;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * assetController 资产信息Controller
 *
 * @author yangshuai
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/system/asset")
public class SysExpendDetailsAssetController extends BaseController
{
    @Autowired
    private ISysExpendDetailsAssetService sysExpendDetailsAssetService;

    /**
     * 查询asset列表 资产信息列表
     *  消费类型 0代理商充值 1商家充值 2商家发起背调扣费 3对应代理商接口调用扣费 不传代表全部
     */
//    @PreAuthorize("@ss.hasPermi('system:asset:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysExpendDetailsAsset sysExpendDetails)
    {

        List<SysExpendDetailsAsset> list = sysExpendDetailsAssetService.selectSysExpendDetailsList(sysExpendDetails);
        return getDataTable(list);
    }

    @PostMapping("/assetBalance")
    public AjaxResult assetBalance(){
        //获取当前登录人的单位id
        Long deptId = SecurityUtils.getDeptId();
        //根据当前登录人的单位id查询资产信息的账户余额
        SysExpendDetailsAsset sysExpendDetailsAsset = new SysExpendDetailsAsset();
        sysExpendDetailsAsset.setDeptId(deptId);
        BigDecimal bigDecimal = sysExpendDetailsAssetService.assetBalance(sysExpendDetailsAsset);
        return AjaxResult.success(bigDecimal);
    }

    /**
     * 导出asset列表
     */
//    @PreAuthorize("@ss.hasPermi('system:asset:export')")
    @Log(title = "asset", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysExpendDetailsAsset sysExpendDetailsAsset)
    {
        startPage();
        List<SysExpendDetailsAsset> list = sysExpendDetailsAssetService.selectSysExpendDetailsList(sysExpendDetailsAsset);

        ExcelUtil<SysExpendDetailsAsset> util = new ExcelUtil<SysExpendDetailsAsset>(SysExpendDetailsAsset.class);
        util.exportExcel(response, list, "asset数据");
    }

    /**
     * 获取asset详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:asset:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysExpendDetailsAssetService.selectSysExpendDetailsById(id));
    }

    /**
     * 新增asset
     */
    @PreAuthorize("@ss.hasPermi('system:asset:add')")
    @Log(title = "asset", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysExpendDetailsAsset sysExpendDetails)
    {
        return toAjax(sysExpendDetailsAssetService.insertSysExpendDetails(sysExpendDetails));
    }

    /**
     * 修改asset
     */
    @PreAuthorize("@ss.hasPermi('system:asset:edit')")
    @Log(title = "asset", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysExpendDetailsAsset sysExpendDetails)
    {
        return toAjax(sysExpendDetailsAssetService.updateSysExpendDetails(sysExpendDetails));
    }

    /**
     * 删除asset
     */
    @PreAuthorize("@ss.hasPermi('system:asset:remove')")
    @Log(title = "asset", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysExpendDetailsAssetService.deleteSysExpendDetailsByIds(ids));
    }
}
